package gui;

import javax.swing.*;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class OperatorView extends JPanel implements ActionListener{
	
	private JButton add = new JButton(" + ");
	private JButton sub = new JButton(" - ");
	private JButton mul = new JButton(" x ");
	private JButton dev = new JButton(" / ");
	CalculatorModel c;
	
	public OperatorView(){
		
		this.setLayout(new GridLayout(4, 1));
		
		this.add(add);			
		this.add(sub);				
		this.add(mul);		
		this.add(dev);
		
		add.addActionListener(this);	
		sub.addActionListener(this);
		mul.addActionListener(this);
		dev.addActionListener(this);		
	}

	
	public void actionPerformed(ActionEvent e) {
		c = (CalculatorModel) e.getSource();	
		
		String firstOp = c.firstOperand();
		String secOp = c.secondOperand();
		String op = ""; 
		
		if(e.getSource() == add){
			op = "+";				
			c.add();				
		}
		if(e.getSource() == sub){
			op = "-";
			c.substract();				
		}
		if(e.getSource() == mul){
			op = "x";				
			c.multiply();				
		}
		if(e.getSource() == dev){
			op = "/";
			c.divide();				
		}
		
		String outputString = "Het antwoord van "+firstOp + " " + op + " " + secOp +" = " + c.secondOperand()+"\n";	
		c.setOutputString(outputString);
	}
	
	
}